package com.zy.service.impl;

import com.zy.entity.dto.RegisterUserDTO;
import com.zy.entity.pojo.User;
import com.zy.enums.BizcExceptionCodeEnum;
import com.zy.exception.BizcException;
import com.zy.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

/**
 * @Author CarreyZhou
 * @Date: 2024/5/3 13:16
 */
@Service
@Slf4j
public class UserService implements IUserService {
    @Override
    public User getUserById(int id) {
        return new User(1, "CarreyZhou", 25, "123@qq.com","13214321543","13214321543");
    }

    @Override
    public String registerUser(RegisterUserDTO registerUserDTO) {
        if ("admin".equals(registerUserDTO.getUsername())){
            throw new BizcException(BizcExceptionCodeEnum.USER_NAME_EXIST.getCode(), BizcExceptionCodeEnum.USER_NAME_EXIST.getDescription());
        }
        User user = new User();
        BeanUtils.copyProperties(registerUserDTO, user);
        log.info("register user: {}", user);
        return "success";
    }
}
